﻿<UserControl x:Class="SABnzbdNET.Views.ServerHistoryView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:c="clr-namespace:SABnzbdNET.Commands"
             mc:Ignorable="d" d:DesignHeight="350" d:DesignWidth="500">
    <UserControl.Resources>
        <c:CommandReference x:Key="DeleteCommandReference" Command="{Binding Path=DeleteCommand}" />
        <ContextMenu x:Key="ContextMenu">
            <MenuItem Header="Delete" Command="{StaticResource DeleteCommandReference}" CommandParameter="{Binding}" />
        </ContextMenu>
    </UserControl.Resources>
    <Grid>
        <GroupBox HorizontalAlignment="Stretch" VerticalAlignment="Top" Header="Server history" >
            <Grid Margin="5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="20" />
                </Grid.RowDefinitions>
                <Image HorizontalAlignment="Right" Name="imgBackground" Opacity="0.15" Stretch="Uniform" VerticalAlignment="Stretch" Grid.Column="1" Grid.Row="0" Grid.RowSpan="7">
                    <Image.Source>
                        <BitmapImage UriSource="/SABnzbdNET;component/Graphics/SABnzbd.jpg"></BitmapImage>
                    </Image.Source>
                </Image>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="0">Server</TextBlock>
                <TextBlock  HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="0">
                    <Hyperlink Command="{Binding Path=LaunchBrowserCommand}">
                        <Run Text="{Binding Source={StaticResource Settings}, Path=Default.ServerPath}" />
                    </Hyperlink>
                </TextBlock>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="1">Status</TextBlock>
                <TextBlock HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="1" Text="{Binding Path=ServerHistory.Status}"></TextBlock>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="2">Latest download</TextBlock>
                <TextBlock HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="2" Text="{Binding Path=FirstJob.Title}"></TextBlock>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="3">Uptime</TextBlock>
                <TextBlock HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="3" Text="{Binding Path=ServerHistory.Uptime}"></TextBlock>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="4">Total download</TextBlock>
                <TextBlock HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="4" Text="{Binding Path=ServerHistory.DownloadTotal}"></TextBlock>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="5">This month</TextBlock>
                <TextBlock HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="5" Text="{Binding Path=ServerHistory.DownloadMonth}"></TextBlock>
                <TextBlock HorizontalAlignment="Left" Grid.Column="0" Grid.Row="6">This week</TextBlock>
                <TextBlock HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="6" Text="{Binding Path=ServerHistory.DownloadWeek}"></TextBlock>
            </Grid>
        </GroupBox>
        <GroupBox HorizontalAlignment="Stretch" Height="165" VerticalAlignment="Bottom" Header="Finished downloads" >
            <Grid>
                <ListView Margin="0,0,0,0" VerticalAlignment="Stretch" ItemsSource="{Binding Path=ServerHistory.FinishedJobs}" >
                    <ListView.ItemContainerStyle>
                        <Style TargetType="{x:Type ListViewItem}">
                            <Setter Property="ContextMenu" Value="{StaticResource ContextMenu}"/>
                        </Style>
                    </ListView.ItemContainerStyle>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="5" Width="515" HorizontalAlignment="Stretch">
                                <TextBlock Margin="0,0,50,0" Text="{Binding Title}" VerticalAlignment="Top" HorizontalAlignment="Stretch" />
                                <TextBlock Margin="0,0,0,0" Text="{Binding Status}" VerticalAlignment="Top" HorizontalAlignment="Right" FontSize="10" />
                                <StackPanel Margin="5,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="290" Orientation="Horizontal" FlowDirection="LeftToRight">
                                    <TextBlock Text="Size: " FontSize="10" />
                                    <TextBlock Text="{Binding Size}" FontSize="10" />
                                    <TextBlock Text=". Category: " FontSize="10" />
                                    <TextBlock Text="{Binding Category}" FontSize="10" />
                                </StackPanel>
                                <TextBlock Margin="0,20,0,0" HorizontalAlignment="Right" VerticalAlignment="Top" Text="{Binding ErrorMessage}" FontSize="10" />
                            </Grid>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Grid>
        </GroupBox>
    </Grid>

</UserControl>
